package com.app.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author xiaoyu.fang
 * @date 2019/12/13 14:49
 */
@Slf4j
@Component
public class RabbitTemplateConfig implements RabbitTemplate.ConfirmCallback {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init() {
        rabbitTemplate.setConfirmCallback(this);
    }

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        log.info("消息唯一标识 >>>>>>>>>>> {}", correlationData);
        log.info("确认结果 >>>>>>>>>> {}", ack);
        log.info("失败原因 >>>>>>>>>> {}", cause);
    }
}
